var vm = new Vue({
  el: '#app',
  data() {
    return {
      msgdata: {
        take: '',
        EatCalories: '',
        NewWeight: '',
        TargetWeight: '',
        cosume: '',
        regular: '',
        fin: [
          {
            calories: '',
            createtime: '',
            fmId: '',
            id: '',
            name: '',
            quanity: '',
            type: '',
            unitid: '',
            userId: '',
            imgurl: '',
          },
        ],
        ein: [
          {
            calories: '',
            createtime: '',
            id: '',
            mmid: '',
            name: '',
            quanity: '',
            type: '',
            userid: '',
            imgurl: '',
          },
        ],
      },
      foodListSign: true,
      foodNullSign: false,
      movListSign: true,
      movNullSign: false,
      currentRate: 0,
      gridvalue: '',
      gradientColor: {
        '0%': '#3fecff',
        '100%': '#6149f6',
      },
    };
  },
  mounted: function () {
    axios.post(`/personUser/getRecord`)
      .then(res = > {
      console.log("res is=>", res.data);
    console.log("res is=>", res.data.toString());
    vm.$data.msgdata.take = res.data.take;
    vm.$data.msgdata.EatCalories = res.data.EatCalories;
    vm.$data.msgdata.NewWeight = res.data.NewWeight;
    vm.$data.msgdata.TargetWeight = res.data.TargetWeight;
    vm.$data.msgdata.cosume = res.data.cosume;
    vm.$data.msgdata.regular = res.data.regular;
    vm.$data.msgdata.fin = res.data.fin;
    vm.$data.msgdata.ein = res.data.ein;
    if (res.data.fin == null || vm.$data.msgdata.fin == "") {
      foodListSign = false;
      foodNullSign = true;
    } else {
      foodListSign = true;
      foodNullSign = false;

      //将图片地址都拼接上require
      for (var i = 0; i < vm.$data.msgdata.fin.length; i++) {
        vm.$data.msgdata.fin[i].imgurl = "../image/userImg/" + vm.$data.msgdata.fin[i].imgurl;
        console.log("this new img " + vm.$data.msgdata.fin[i].imgurl);
      }
    }
    if (res.data.ein == null || vm.$data.msgdata.ein == "") {
      movListSign = false;
      movNullSign = true;

    } else {
      movNullSign = false;
      movListSign = true;

      for (var j = 0; j < vm.$data.msgdata.ein.length; j++) {
        vm.$data.msgdata.ein[j].imgurl = "../image/userImg/" + vm.$data.msgdata.ein[j].imgurl;
        console.log("this eee new img " + vm.$data.msgdata.ein[j].imgurl);
      }
    }
    // console.log(vm.$data.ModelUnitAndIfo);
    if (res.data.returnMsg != null)
      alert(res.data.returnMsg.toString());
  }
  )
  },
  methods: {
    onClickLeft() {
      Toast('返回');
    },
    toPersonalCenter() {
      window.location.href = "toPersonalCenter";
    },
    toLookforfood() {
      window.location.href = "toLookforfood";
    },
    toLookforMov() {
      window.location.href = "tolookformov";
    },
    deleteMov(index) {
      let postdata = {
        movInstanceId: vm.$data.msgdata.ein[index].id,

      };
      console.log("this id is" + postdata.movInstanceId);
      axios.post(`/movuser/deleteMovInstance`, Qs.stringify(postdata))
        .then(res = > {
        console.log("res is=>", res.data);
      console.log("res is=>", res.data.toString());
      // console.log(vm.$data.ModelUnitAndIfo);
      if (res.data.returnMsg != null) {
        alert(res.data.returnMsg.toString());
        if (res.data.returnMsg == "删除成功") {
          vm.$data.msgdata.ein.splice(index, 1)
        }
      }
      ;

    }
    )
    },
    deleteFood(index) {
      let postdata = {
        FoodInstanseId: vm.$data.msgdata.fin[index].id,
      };
      axios.post(`/fooduser/deleteFoodInstanse`, Qs.stringify(postdata))
        .then(res = > {
        console.log("res is=>", res.data);
      console.log("res is=>", res.data.toString());
      // console.log(vm.$data.ModelUnitAndIfo);
      if (res.data.returnMsg != null) {
        alert(res.data.returnMsg.toString());
        if (res.data.returnMsg == "你成功把食物吐出来了，我就当你没吃过！") {
          vm.$data.msgdata.fin.splice(index, 1)
        }
      }
    }
    )
    }
  },
  computed: {
    text() {
      return this.currentRate.toFixed(0) + '%';
    },
  },
});
